<?php
class BusinessAction extends BusinessWechatAction {

	/* 控制器 登录 */
	// 店长主页	// 店员主页
	public function index() {
	    $code=$_REQUEST['code'];

	    $secret=C('SECRET');
	    $appid=C('APPID');
	    $url="https://api.weixin.qq.com/sns/oauth2/access_token?appid=$appid&secret=$secret&code=$code&grant_type=authorization_code ";
		$info=$this->Get($url);
		$info=json_decode($info,true);
		$tel=$_SESSION['tel1'];
		$id=$_SESSION['id'];
		$openid['openid']=$info["openid"];
        $user=M('admin_business')->where("id=$id")->save($openid);
// 		dump($_SESSION);exit;
		$conti[0]="f.shop_id=b.shop_id";
		$conti[1]="b.tel=$tel";
		$conti[2]="f.time>".strtotime( date('Y-m-d') );
		$conti[3]="f.time<".strtotime( date('Y-m-d',strtotime('+1 day')) );
		$data=M()->table('qq_admin_business b,qq_user_footprint f')->where($conti)->sum("f.used_money");
//		dump($data);
		$cont[0]="ab.shop_id=b.business_id";
		$cont[1]="ab.tel=$tel";
		$list=M()->field('b.business_id,b.property,ab.withdraw,ab.purview')->table('qq_admin_business ab,qq_business b')->where($cont)->find();
		$a=$list[property]-$list[withdraw];
// 		dump($list);exit;
		$_SESSION['b_id'] = $list['business_id'];
		$b_id=$_SESSION['b_id'];
		$id=$_SESSION['id'];
		$times=strtotime( date('Y-m-d') );
// 		dump($times);exit;
		$data1=M('card6')->where("shop_id=$b_id")->count();
	
		
		$data2=M('card6')->field("id")->where("shop_id=$b_id  and UNIX_TIMESTAMP(creattime)>$times")->count();
		
		$b_id=$_SESSION['b_id'];
		$cont1[0]="shop_id=$b_id";
		$cont1[1]="status=0";
		$list1=M('user_footprint')->where($cont1)->count();
		
// 		dump($list1);exit;
		$this->assign('a',$a);
		$this->assign('tel',$tel);
		$this->assign('list1',$list1);
		$this->assign('data',$data);
		$this->assign('data1',$data1);
		$this->assign('data2',$data2);
		$this->assign('list',$list);
		$this->display();
		
	}
	public function index_ajax(){
// 	    $this->ajaxReturn(3);exit;
	    $user='"'."$_SESSION[user_info]".'"';
	    $uid='"'."$_SESSION[user_id]".'"';
	    $stale=M('stale1')->order('id desc')->find();
	    // dump($stale['status']);exit;
	    // if($stale['status']==1){
	
	    // 	// $this->redirect('wypj?uid='.$uid.'&&sid='.$stale['bid']);
	    // 	$this->redirect('myerwei');
	    // }
	    if($stale){
	        $this->ajaxReturn($stale);
	    }
	}
	public function success(){
	    $sid=$_GET[_URL_][6];
	    $uid=$_GET[uid];
	    $cid=$_GET[cid];
	    $status=$_GET[status];
	    if($status==1){
	        $statuss=1;
	    }
// 	    dump($statuss);
// 	  
	    $stale=M('stale1')->where("uid=$uid")->order('id desc')->find();
// 	    dump($stale);exit;
	    $jilu=$stale['stale'];
	    if(!$jilu){
	        $this->redirect('index');exit;
	    }
	    $data=M('user_footprint')->field('time,savemoney')->where("id=$jilu")->find();
	    $data2=M("user")->where("user_id=$uid")->find();
	    $data3=M('card6')->where("shop_id=$sid and user_id=$uid and coupon_id=$cid")->find();
	    // 		$shop_id=$data[shop_id];
	    $data1=M('business')->where("business_id=$sid")->find();
	    M('stale1')->where("uid=$uid")->delete();
	    
	    $this->assign('data',$data);
	    $this->assign('data1',$data1);
	    $this->assign('data2',$data2);
	    $this->assign('data3',$data3);
	    $this->assign('statuss', $statuss);
// 	    dump($statuss);exit;
	    $this->display();
	}
	
	//我的资产
	public function myAsset() {
		$tel=$_SESSION['tel1'];
		$cont[0]="ab.shop_id=b.business_id";
		$cont[1]="ab.tel=$tel";
		$list=M()->field('b.business_id,b.property,ab.withdraw')->table('qq_admin_business ab,qq_business b')->where($cont)->find();
// 		dump($list);exit;
		$withdraw=M('withdraw_deposit');
		$cont[0]="shop_id=$list[business_id]";
		$cont[1]="status=0"; 	
		$data=$withdraw->where($cont)->sum("money");
		
		
		$b_id=$_SESSION['b_id'];
		$cont1[0]="shop_id=$b_id";
		$cont1[1]="status=0";
		
		$num=M('b_detail')->where($cont1)->count();
// 		dump($data);exit;
		$this->assign('data',$data);
		$this->assign('list',$list);
		$this->assign('num',$num);
		$this->display();
	}
	
	//商家续费vip
	public function renewVip() {
	
		$this->display();
	}
	//银行选择
	public function deposit1() {
		$_SESSION['bank']=$_POST['bank'];
		$this->ajaxReturn('1');
	}
	//开户地选择
	public function deposit2() {
		$_SESSION['address']=$_POST['address'];
		$this->ajaxReturn('1');
	}
	//提现
	public function deposit() {
		$tel=$_SESSION['tel1'];
		$cont[0]="ab.shop_id=b.business_id";
		$cont[1]="ab.tel=$tel";
		$list=M()->field('b.business_id,b.property,ab.withdraw,ab.purview,ab.enwithdraw')->table('qq_admin_business ab,qq_business b')->where($cont)->find();
// 		dump($list);exit;
		$this->assign('list',$list);	
		$this->display();
	}
	//其他提现
	public function elseDeposit() {
		
		$tel=$_SESSION['tel1'];
// 		dump($tel);exit;
		if(empty($tel)){
			$this->redirect('User/userLogin');
		
		}
		$cont[0]="ab.shop_id=b.business_id";
		$cont[1]="ab.tel=$tel";
		$list=M()->field('b.business_id,b.property,ab.withdraw,ab.purview,ab.enwithdraw')->table('qq_admin_business ab,qq_business b')->where($cont)->find();
		$this->assign('list',$list);	
		$this->display();
	}
	//提现处理
	public function toDeposit() {
// 		dump($_POST);exit;
		if(empty($_POST['num'])	|| empty($_POST['address']) ||  empty($_POST['bank']) ||  empty($_POST['money']) ||  empty($_POST['name'])){
					$this->error('信息没有填写完整');
			  	}
		if($_POST['money']==0||!is_numeric($_POST['money'])){
			$this->error('输入的金额有误');
		}
		$data['shop_id']=$_SESSION['b_id'];
		$data['card_num']=$_POST['num'];
		$data['address']=$_POST['address'];
		$data['bank']=$_POST['bank'];
		$data['name']=$_POST['name'];
		$data['money']=$_POST['money'];
		$tel=$_SESSION['tel1'];
		$list=M('admin_business')->where("tel=$tel")->find();
// 		dump($list);exit;
		$shop_id=$list['shop_id'];
		$res=M('business')->field('property')->where("business_id=$shop_id")->find();
// 		dump($res['property']);exit;
		if($list['enwithdraw']<=0){
			$this->error('余额不足');
		}
		$withdraw=$list['withdraw']+$data['money'];
		$data1['withdraw']=$withdraw;
		$data1['enwithdraw']=$list['enwithdraw']-$data['money'];
		M('admin_business')->where("tel=$tel")->save($data1);
		$data=M('withdraw_deposit')->add($data);
		if($data>0){
			$this->redirect('Business/withdrawDeposit');	
				}
	}
	
	//其他提现处理
	public function toDeposit2() {
// 		dump($_POST);exit;
		if(empty($_POST['num'])  ||  empty($_POST['money']) ||  empty($_POST['name'])){
			$this->error('信息没有填写完整');
		}
		$data['shop_id']=$_SESSION['b_id'];
		$data['alipay']=$_POST['num'];
		$data['aliname']=$_POST['name'];
		$data['money']=$_POST['money'];
		$tel=$_SESSION['tel1'];
		$list=M('admin_business')->field('withdraw,shop_id,enwithdraw')->where("tel=$tel")->find();
		$shop_id=$list['shop_id'];
		$res=M('business')->field('property')->where("business_id=$shop_id")->find();
		// 		dump($res['property']);exit;
		if($list['enwithdraw']<=0){
			$this->error('余额不足');
		}
		$withdraw=$list['withdraw']+$data['money'];
		$data1['withdraw']=$withdraw;
		$data1['withdraw']=$list['enwithdraw']-$data['money'];
		M('admin_business')->where("tel=$tel")->save($data1);
		$data=M('withdraw_deposit')->add($data);
		if($data>0){
			$this->redirect('Business/withdrawDeposit');	
				}
	}
	public function withdrawDeposit() {
		$this->display();
	}
	// 员工下来加载
	public function employeeRefresh() {
		$lim=$_POST['limit'];
	
		$b_id=$_SESSION['b_id'];
	
		$list=M('admin_business')->field('nickname,tel,id,purview,collection')->where("shop_id=$b_id")->limit(10,25)->select();
	
		$this->ajaxReturn($list);
	}
	// 会员下拉加载1／3页面
	public function employeeRefresh1() {
		$lim=$_POST['limit'];
		
		$b_id=$_SESSION['b_id'];
//		$list=M('member')->field('user_id,creattime,endtime,discount,lasttime,username,usertel,birthday')->where("shop_id=$b_id")->order('user_id')->limit($lim,5)->select();
		
		$data=M()->field('u.user_id,c.id,c.creattime,u.nickname,c.count,user_name')->table('qq_card6 c,qq_user u')->where("c.shop_id=$b_id and c.user_id=u.user_id")->order('c.id')->limit($lim,5)->select();
// 		dump($data);exit;
		$this->ajaxReturn($data);
	}
	// 会员下拉加载2／3页面
	public function employeeRefresh2() {
		$lim=$_POST['limit'];
		$b_id=$_SESSION['b_id'];
		$data=M()->field('u.user_id,c.id,c.creattime,u.nickname,c.count,user_name')->table('qq_card6 c,qq_user u')->where("c.shop_id=$b_id and c.user_id=u.user_id")->order('c.creattime desc')->limit($lim,5)->select();
		$this->ajaxReturn($data);
	}
	// 会员下拉加载3／3页面
	public function employeeRefresh3() {
		$lim=$_POST['limit'];
		$b_id=$_SESSION['b_id'];
		$data=M()->field('u.user_id,c.id,c.creattime,u.nickname,c.count,user_name')->table('qq_card6 c,qq_user u')->where("c.shop_id=$b_id and c.user_id=u.user_id")->order('c.count desc')->limit($lim,5)->select();
		$this->ajaxReturn($data);
	}
	//卡券交易明细
	public function detail() {
		$b_id=$_SESSION['b_id'];
		$cont[0]="shop_id=$b_id";
		
		$list=M('b_detail')->field()->where($cont)
		->order("id desc")
		->limit(0,10)
		->order('id desc')
		->select();
// 		dump($list);exit;
        $data['status']="1";
		$sum=M('b_detail')->where($cont)->save($data);
		$this->assign('list',$list);

	
		//		dump($list2);
		$this->display();
	}

	
	
	//卡券交易明细
	public function detail_fresh() {
		$lim=$_POST['limit'];
		$b_id=$_SESSION['b_id'];
		$list=M('b_detail')->field()->where($cont)
		->order("id desc")
		->limit($lim,10)
		->order('id desc')
		->select();
		$this->assign('list',$list);
		$this->ajaxReturn($list);
	}
	
	//交易明细
	public function details() {
		$b_id=$_SESSION['b_id'];
// 		dump($b_id);exit;
		$cont[0]="shop_id=$b_id";
		$list1=M('user_footprint')->where($cont)->count();
// 		dump($list1);exit;
		$list=M('user_footprint')->field('id,used_money,time,name,tel,user_id')->where($cont)
		->order("id desc")
		->limit(0,10)->select();
		$data['status']="1";
		$list3=M('user_footprint')->where($cont)->save($data);
		$tel=$_SESSION['tel1'];
		$cont[0]="ab.shop_id=b.business_id";
		$cont[1]="ab.tel=$tel";
		$list2=M()->field('ab.purview')->table('qq_admin_business ab,qq_business b')->where($cont)->find();
// 		dump($list2);exit;
		$this->assign('list',$list);	
		$this->assign('list1',$list1);	
		$this->assign('list2',$list2);
//		dump($list2);
		$this->display();
	}
	//下拉加载跟更多交易明细
	public function employeeRefresh_details() {
		$lim=$_POST['limit'];
		$b_id=$_SESSION['b_id'];
		$list=M('user_footprint')->field('id,user_id,used_money,time,name,tel')->where("shop_id=$b_id")
		->limit($lim,10)
		->order("id desc")
		->select();
		$this->ajaxReturn($list);
	}
	//员工查看的交易明细
	public function detailss() {
		$b_id=$_SESSION['b_id'];
		$id=$_SESSION['id'];
		$cont[0]="shop_id=$b_id";
		$cont[1]="business_id=$id";
		$list1=M('user_footprint')->where($cont)->count();
		$list=M('user_footprint')->field('user_id,used_money,time,name,tel')->where($cont)->limit(0,20)->select();
		$this->assign('list',$list);	
		$this->assign('list1',$list1);	
//		dump($list2);
		$this->display();
	}
	//下拉加载跟更多交易明细(员工)
	public function employeeRefresh_detailss() {
		$lim=$_POST['limit'];
		$id=$_SESSION['id'];
		$b_id=$_SESSION['b_id'];
		$list=M('user_footprint')->field('user_id,used_money,time,name,tel')->where("shop_id=$b_id and business_id=$id")->limit($lim,5)->select();
		$this->ajaxReturn($list);
	}
	//个人信息查看
	public function person1() {
		$tel=$_SESSION['tel1'];
		$data=M('admin_business')->field('tel,nickname,purview')->where("tel=$tel")->find();
		$this->assign('data',$data);
		$this->display();
	}
	//个人信息修改保存
	public function savePerson1() {
		$tel=$_SESSION['tel1'];
		$te="tel=$tel";
		$name1['nickname']=$_POST['name'];
		$data=M('admin_business')->where($te)->save($name1 );
		$this->redirect('index');
		
	}
	
	
	
	//修改手机号
	public function edittel() {
		$tel=$_GET['tel'];
		$yzm=$_GET['yz'];
		$tel1=$_SESSION['tel1'];
		$code=M('sms')->field()->where("to_phone=$tel and isused=0")->order('time desc')->find();
	
// 				dump($code);exit;
		if($code['desc']==$yzm){
			$data[tel]=$tel;
			$list=M('admin_business')->where("tel=$tel")->find();
		
			if($list){
				$this->error('号码已存在');
			}
			// 			dump($code['id']);exit;
			$list=M('admin_business')->where("tel=$tel1")->save($data);
			// 			$data1['isused']=1;
			// 			M('sms')->where("id=$id")->save($data1);
			if($list>0){
				 $this->esc();
			}else{
				$this->error('修改失败');
			}
		}else{
			$this->error('验证码错误');
		}
	
	}
	//商店信息
	public function shopMessage() {
		$b_id=$_SESSION['b_id'];
		$data=M('business')->field('business_name,address,open')->where("business_id=$b_id")->find();
		$tel=$_SESSION['tel1'];
		$data1=M('admin_business')->field('purview')->where("tel=$tel")->find();
		$this->assign('data',$data);
		$this->assign('data1',$data1);
		$this->display();
	}
	
	// 员工管理
	public function pullrefresh_sub() {
		$b_id=$_SESSION['b_id'];
		$data=M('admin_business')->field('nickname,tel,id,purview,collection')->where("shop_id=$b_id and purview!=0")->limit(0,10)->select();
	
		$this->assign('data',$data);
		$this->display();
	}
	//员工权限设置
	public function setPermissione(){
		$id=$_POST['permission'];
		$list['purview']=$_POST['status'];
		M('admin_business')->where("id=$id")->save($list);
		$data=M('admin_business')->field('purview')->where("id=$id")->find();
		$this->ajaxReturn($data);
	}
	// 扫码购买卡券
	public function payErwei() {
		$b_id=$_SESSION['b_id'];
		$data[1]="business_id=$b_id";
		$data[2]="erwei!=''";
		$data=M('coupon')->where($data)->order('coupon_id desc')->select();
		$data=$data[0];
		$tel=$_SESSION['tel1'];
		$cont[0]="ab.shop_id=b.business_id";
		$cont[1]="ab.tel=$tel";
		$list2=M()->field('ab.purview')->table('qq_admin_business ab,qq_business b')->where($cont)->find();
		$this->assign('data',$data);
		$this->assign('list2',$list2);
		$this->display();
	}
	//	扫我享受折扣
	public function discountErwei() {
		$tel=$_SESSION['tel1'];
		$data=M('admin_business')->where("tel=$tel")->find();
		$list1=$data['id'];
		$sid=$data['shop_id'];
		
		if (!$data['erwei']) {
		
			vendor("phpqrcode.phpqrcode");
            $data1 = C(WEB_URL).'wechat/User/zhekou?aid='.$list1.'&&sid='.$sid;
            // 纠错级别：L、M、Q、H
            $level = 'L';
            // 点的大小：1到10,用于手机端4就可以了
            $size = 4;
            // 下面注释了把二维码图片保存到本地的代码,如果要保存图片,用$fileName替换第二个参数false
            $path = "upload/admin_erwei/";
            if (!is_dir($path)) {
			mkdir($path);
			}
            // 生成的文件名
            $fileName = $path.time().'.png';
            
           	$list['erwei']=$fileName;
           	$erwei=M('admin_business')->where("tel=$tel")->save($list);
        
            QRcode::png($data1, $fileName, $level, $size);
			
		}
		
		
		$cont[0]="ab.shop_id=b.business_id";
		$cont[1]="ab.tel=$tel";
		$list2=M()->field('ab.purview')->table('qq_admin_business ab,qq_business b')->where($cont)->find();
		$this->assign('data',$data);
		$this->assign('list2',$list2);
		$this->display();
	}
	//会员详情
	
	public function memberDetails() {
		$uid=$_GET['id'];
// 		$uid=864;
		$b_id=$_SESSION['b_id'];
		$data=M()->table('qq_user  as  u')->join("qq_card6 as c ON c.user_id=u.user_id")->where("u.user_id=$uid")->order('id desc')->find();
// 		dump($data);exit;
		$tel=$_SESSION['tel1'];
		$cont[0]="ab.shop_id=b.business_id";
		$cont[1]="ab.tel=$tel";
		$list2=M()->field('ab.purview')->table('qq_admin_business ab,qq_business b')->where($cont)->find();
		$this->assign('data',$data);
		$this->assign('list2',$list2);
		$this->display();
		
	}
	//会员管理（店主）
	public function manage() {
		$b_id=$_SESSION['b_id'];
		$data=M()->field('u.user_id,c.id,c.creattime,u.nickname,c.count,user_name')->table('qq_card6 c,qq_user u')->where("c.shop_id=$b_id and c.user_id=u.user_id")->order('c.id')->limit(0,10)->select();
		$data1=M()->field('u.user_id,c.id,c.creattime,u.nickname,c.count,user_name')->table('qq_card6 c,qq_user u')->where("c.shop_id=$b_id and c.user_id=u.user_id")->order('c.creattime desc')->limit(0,10)->select();
		$data2=M()->field('u.user_id,c.id,c.creattime,u.nickname,c.count,user_name')->table('qq_card6 c,qq_user u')->where("c.shop_id=$b_id and c.user_id=u.user_id")->order('c.count desc')->limit(0,10)->select();
// 		dump($data);exit;
		$tel=$_SESSION['tel1'];
		$cont[0]="ab.shop_id=b.business_id";
		$cont[1]="ab.tel=$tel";
		$list2=M()->field('ab.purview')->table('qq_admin_business ab,qq_business b')->where($cont)->find();
// 		
		$this->assign('time',$time);
		$this->assign('data',$data);
		$this->assign('list2',$list2);
		$this->assign('data1',$data1);
		$this->assign('data2',$data2);
		$this->display();
	}
	//我的会员（店员）
	public function manage_2(){
		$b_id=$_SESSION['b_id'];
		$id=$_SESSION['id'];
//		$data=M('member')->field('user_id,creattime,endtime,discount,lasttime,username,usertel,birthday')->where("shop_id=$b_id and business_id=$id")->select();
		$data=M()->field('c.id,c.creattime,u.nickname,c.count,user_name')->table('qq_card6 c,qq_user u')->where("c.shop_id=$b_id and c.user_id=u.user_id")->select();
//		dump($data);exit;
		$this->assign('data',$data);
		$this->display();
	}
	//执行登陆
	public function toLogin() {
		
	
		$b_admin=M('admin_business');
		$data=$b_admin->field('id,tel,shop_id,purview')->where("tel=$_POST[tel]")->find();
		$list=M('sms')->field('desc')->where("to_phone=$_POST[tel]")->order("id desc")->find();

		if($data["purview"] ==2){
			$this->error('账号还未通过审核');
		}
		if(empty($data['tel'])){
			$this->error('账号不存在');
		}
		
		if($list['desc']!=$_POST[yam]){
			$this->error('验证码错误');
		}
		$shop_id=$data['shop_id'];
		
		$b_business=M('business')->field('statuss')->where("business_id=$shop_id")->find();
		$res=$b_business['statuss'];
		if($res==2){
			$this->error('该店还未通过审核');
		}
		$_SESSION['tel1'] = $data[tel];
		$_SESSION['id'] = $data[id];
		
		$send =A('Wechat/Oauth');
		$send->openid();
		
// 		$this->redirect('Business/index');
	
		
		
	}
	//退出
	public function esc(){
		session(null);  
        $this->redirect('business/logins');  
	}
	//验证
	
	public function telyz() {
		$arr =json_encode($_POST['tel']);
		$arr=substr($arr, 1,11);
		if (!is_numeric($arr)) {
	       $this->ajaxReturn('3');
	    }
		if(preg_match("/^1[34578]{1}\d{9}$/",$arr)){  
		    $data=M('member')->field('id')->where("usertel=$arr")->select();
			if($data){
				$this->ajaxReturn('1');//手机号有效
			}else{
				$this->ajaxReturn('2');//手机号已经注册
			}
		
		}else{  
		    		$this->ajaxReturn('3');//手机号格式错误
				}  
	
	}
	//登陆页面
// 	public function logins() {
		
// 		$this->display();
		
// 	}
		public function login() {
		
		$this->display();
		
	}
	//注册
	public function register() {
		$arr =json_encode($_POST['tel']);
		$list['usertel']=$arr;
		if(preg_match("/^1[34578]{1}\d{9}$/",$arr)){  
		    $data=M('member')->data($list)->add();
			if($data){
			$this->ajaxReturn('1');
		}else{
			$this->ajaxReturn('2');
			}
		
		}

		
	}
		//扫描顾客的二维码
		public function user(){
		
			$uid=$_REQUEST['uid']; //用户id
			// dump($uid);exit;
			$inform = M('user');
			$rus = $inform->where("user_id=$uid")->find();
			// dump($rus);exit;
			$name=$rus['nickname'];
			$user_tel=$rus['user_name'];
			$id=$_SESSION[id];				//店员id	
			$b_id=$_SESSION['b_id'];//	商店id
		// dump($b_id);exit;

			$list2=M('card6')->where("shop_id=$b_id and user_id=$uid")
			->order('coupon_id desc')
			->find();
			// dump($b_id);exit;
			$list1=M('coupon')->where("business_id=$b_id")
			->order('coupon_id desc')
			->find();//这里局限了 商家只能有一种卡券 ,以后变多卡券 这里逻辑要修改
			// dump($list1);exit;
			//这里创建一个商家和顾客的状态表,方便之后回调
			$coupon_id=$list1[coupon_id];
			$stale['uid']=$uid;
			$stale['cid']=$coupon_id;
			$stale['bid']=$b_id;
			$stale_rus=M('stale')->add($stale);
			
			if(!$list2){
				$stale2['status']=2;
				$stale_rus2=M('stale')->where("id=$stale_rus")->save($stale2);
				$this->error('优惠次数不足','index');
			}


			
			
			if(!$stale_rus){
				$this->error('重新扫码','index');
			}
			
			$coupon=M('coupon')->field('old_price')->where("coupon_id=$coupon_id")->find();
			$sm=$coupon['old_price'];
		
			// dump($list1);exit;
			if($list2['count']<1){
				$stale2['status']=2;
				$stale_rus2=M('stale')->where("id=$stale_rus")->save($stale2);
				$this->error('优惠次数不足','index');
			}
			$count=$list2['count']-1;
			$id=$list2['id'];
// 			dump($id);exit;
			$data['count']=$count;
			$list2=M('card6')->where("id=$id")->save($data);
			$data1['user_id']=$uid;
			$data1['shop_id']=$b_id;
			$data1['business_id']=$id;
			$data1['name']=$name;
			$data1['tel']=$user_tel;
			$data1['savemoney']=$sm;
			$list3=M('user_footprint')->add($data1);
			// $_SESSION['jilu']=$list3;
			$stale2['stale']=$list3;
			M('stale')->where("id=$stale_rus")->save($stale2);
			if($list3){
				
				$stale2['status']=1;
				$stale_rus2=M('stale')->where("id=$stale_rus")->save($stale2);
				$this->success('扫描成功','index');
			}
				
			 
	}
	
		//添加员工
		public function addstaff(){
//			dump($_SESSION);exit;	
// 			dump($_POST);exit;
			$yzm=$_POST['yzm'];
			$tel=$_POST['tel'];
			$code=M('sms')->field()->where("to_phone=$tel and isused=0")->order('time desc')->find();
			if(!$code){
				$this->error('验证码错误');
			}
			$list=M('admin_business')->where("tel=$tel")->find();
			if($list){
				$this->error('该手机号已经被注册');
			}
			$data['tel']=$_POST['tel'];
			$data['purview']=2;
			$data['password']=md5('123456');
			$data['shop_id']=$_SESSION['b_id'];
			$list1=M('admin_business')->add($data);
			vendor("phpqrcode.phpqrcode");
            $data1 = C(WEB_URL).'wechat/User/zhekou?aid='.$list1.'&&sid='.$_SESSION['b_id'];
            // 纠错级别：L、M、Q、H
            $level = 'L';
            // 点的大小：1到10,用于手机端4就可以了
            $size = 4;
            // 下面注释了把二维码图片保存到本地的代码,如果要保存图片,用$fileName替换第二个参数false
            $path = "upload/admin_erwei/";
            if (!is_dir($path)) {
			mkdir($path);
			}
            // 生成的文件名
            $fileName = $path.time().'.png';
            
           	$list['erwei']=$fileName;
           	$erwei=M('admin_business')->where("tel=$tel")->save($list);
        
            QRcode::png($data1, $fileName, $level, $size);
			if($erwei){
				$this->redirect('pullrefresh_sub');
			}
	}
	
	
	public   function Get($url)
	{
	    if(function_exists('file_get_contents'))
	    {
	        $file_contents = file_get_contents($url);
	    }
	    else
	    {
	        $ch = curl_init();
	        $timeout = 5;
	        curl_setopt ($ch, CURLOPT_URL, $url);
	        curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
	        curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
	        $file_contents = curl_exec($ch);
	        curl_close($ch);
	    }
	    return $file_contents;
	}
	
}
?>